package com.activenetwork.smlite.testcase.login;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.activenetwork.smlite.page.LoginPage;
import com.activenetwork.smlite.page.event.EventsHomeView;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.verification.gson.FailurePoint;

public class Login009 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(Login009.class);
	
	@Test
	public void Check_user_can_sign_in_by_press_Enter(){
		LoginPage loginPage = LoginPage.getCurrentPage(env.getTestEnvironment().getMainSite().getUrl());
		String loginUser = env.getTestEnvironment().getMainSite().getUser().get(0).getName();
		String loginPwd = env.getTestEnvironment().getMainSite().getUser().get(0).getPwd();
		loginPage.inputUserName(loginUser);
		loginPage.inputUserPassword(loginPwd);
		
		//click enter by using robot
		Robot robot;
		try {
			robot = new Robot();
			robot.keyPress(KeyEvent.VK_ENTER);
			robot.keyRelease(KeyEvent.VK_ENTER);
		} catch (AWTException e) {
			e.printStackTrace();
		}

		
		EventsHomeView eventsHomeView = PageLoader.load(EventsHomeView.class);
		String loggedIn = eventsHomeView.getLoggeredInUser();
		
		if(!StringUtils.contains(loggedIn, "Logged in as:")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					Login009.class.getName(), 
					"Verify user can sign in by click enter", 
					"User can not sign in by click enter"));
		}
		
		//logout
		loginBusiness.logout();
	}
	
	

}
